import java.util.*;

public class Solution {
    public String reverseWords(String s) {
        String[] arr = s.trim().split("\\s+");
        StringBuilder res = new StringBuilder();
        for (int i = arr.length - 1; i >= 0; --i) {
            res.append(" ").append(arr[i]);

        }
        return res.toString().trim();
    }

    public String reverseWords2(String s) {
        // 除去开头和末尾的空白字符
        s = s.trim();
        // 正则匹配连续的空白字符作为分隔符分割
        List<String> wordList = Arrays.asList(s.split("\\s+"));  // 只要不涉及删增就行
        Collections.reverse(wordList);
        return String.join(" ", wordList); // 后面是迭代器或者CharSequece(String、SBder、SBfer)
    }


}
